package a66weding.com.jiehuntong.fragment;


import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;

import com.baidu.mapapi.map.BitmapDescriptor;
import com.baidu.mapapi.map.BitmapDescriptorFactory;
import com.baidu.mapapi.map.MapView;
import com.baidu.mapapi.map.MarkerOptions;
import com.baidu.mapapi.map.OverlayOptions;
import com.baidu.mapapi.model.LatLng;
import com.baidu.mapapi.search.core.PoiInfo;
import com.baidu.mapapi.search.poi.OnGetPoiSearchResultListener;
import com.baidu.mapapi.search.poi.PoiCitySearchOption;
import com.baidu.mapapi.search.poi.PoiDetailResult;
import com.baidu.mapapi.search.poi.PoiDetailSearchOption;
import com.baidu.mapapi.search.poi.PoiResult;
import com.baidu.mapapi.search.poi.PoiSearch;

import java.lang.ref.SoftReference;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.List;

import a66weding.com.jiehuntong.R;
import a66weding.com.jiehuntong.activity.ToolsWedRegisterActivity;
import a66weding.com.jiehuntong.beans.WedRegistryMapBean;
import a66weding.com.jiehuntong.common.CommonAdapter;
import a66weding.com.jiehuntong.common.MyViewHolder;
import a66weding.com.jiehuntong.common.utils.CUtils;

/**
 * @version :
 * @creator : AxDu
 * @create-time : 2016/6/7
 * @description :
 */
public class Tools_WedRegLocationFragment extends BaseToolsDayPlanFragment implements View.OnClickListener {
    private ToolsWedRegisterActivity mRegistryActivity;
    private MapView mMapview;
    private View pop;
    private TextView title;
    private ImageView mBackIv;
    private WedRegistryMapBean wedRegistryMapBean;

    private WedRegistryMapBean mCurrentMapBean;


    private List<WedRegistryMapBean> addressList;


    private View mContentView;


    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mRegistryActivity= (ToolsWedRegisterActivity) getActivity();
    }



    @Override
    public View initView() {
        mContentView = View.inflate(mRegistryActivity,R.layout.pager_tools_wedregister_mapinfo, null);

        mMapview = (MapView) mContentView.findViewById(R.id.bmapview_screeen);
        mBackIv = (ImageView) mContentView.findViewById(R.id.iv_tools_wedreg_back);

        mRegistryActivity.setmMapView(mMapview);

        mBackIv.setOnClickListener(this);
        return mContentView;
    }




    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        initData();

    }

    @Override
    public void initData() {

        String cityName = mRegistryActivity.getCityName();

        //定义Maker坐标点



        //构建Marker图标

        wedRegistryMapBean=mRegistryActivity.getmCurrentMapBean();

        String address = wedRegistryMapBean.getAddress();
        String title = wedRegistryMapBean.getTitle();

        View popview = View.inflate(mActivity, R.layout.map_pop, null);
        TextView titleTv = (TextView) popview.findViewById(R.id.name);
        titleTv.setText(title);
        TextView addrTv = (TextView) popview.findViewById(R.id.addr);
        addrTv.setText(address);

        Bitmap bitmap= getViewBitmap(popview);

        BitmapDescriptor bitmapDescriptor = BitmapDescriptorFactory.fromBitmap(bitmap);

        OverlayOptions option = new MarkerOptions().position(wedRegistryMapBean.getLocation()).icon(bitmapDescriptor);

        mMapview.getMap().addOverlay(option);




    }

    private void initPop() {
        pop = View.inflate(mActivity, R.layout.map_pop, null);
        title = (TextView) pop.findViewById(R.id.name);


        MapView.LayoutParams params = new MapView.LayoutParams(MapView.LayoutParams.WRAP_CONTENT,
                MapView.LayoutParams.WRAP_CONTENT);

        mMapview.addView(pop, params);



    }

    private Bitmap getViewBitmap(View addViewContent) {

        addViewContent.setDrawingCacheEnabled(true);

        addViewContent.measure(
                View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED),
                View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED));
        addViewContent.layout(0, 0,
                addViewContent.getMeasuredWidth(),
                addViewContent.getMeasuredHeight());

        addViewContent.buildDrawingCache();
        Bitmap cacheBitmap = addViewContent.getDrawingCache();
        Bitmap bitmap = Bitmap.createBitmap(cacheBitmap);

        return bitmap;
    }




    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.iv_tools_wedreg_back:
                mRegistryActivity.getSupportFragmentManager().popBackStack();


        }
    }



}
